<?php

include_once 'actions.class.php';

class Mysql_conn implements Actions {

    public $dbconn = null;

    function Mysql_conn($dbconn) {
        $this->setDbconn($dbconn);
    }

    public function close($dbconn) {
        @mysql_close($dbconn);
    }

    public function connect($stringConn) {
        if (!$conn = @mysql_connect($stringConn, '', ''))
            echo 'No se pudo establecer conexion con la base de datos';
        return ($conn);
    }

    public function execute($sql) {
        $res = @mysql_query($sql, $this->dbconn);
        if (!$res) {
            echo mysql_error();
            $this->close($this->dbconn);
            exit();
        }
        return $res;
    }

    public function fetchArrayAssoc($arr) {
        $rsp = array();
        while ($line = @mysql_fetch_array($arr, MYSQL_ASSOC)) {
            array_push($rsp, $line);
        }
        @mysql_free_result($arr);
        return ($rsp);
    }

    public function fetchArrayBoth($arr) {
        $rsp = array();
        while ($line = @mysql_fetch_array($arr, MYSQL_BOTH)) {
            array_push($rsp, $line);
        }
        @mysql_free_result($arr);
        return ($rsp);
    }

    public function fetchArrayNum($arr) {
        $rsp = array();
        while ($line = @mysql_fetch_array($arr, MYSQL_NUM)) {
            array_push($rsp, $line);
        }
        @mysql_free_result($arr);
        return ($rsp);
    }

    public function setDbconn($dbconn) {
        $this->dbconn = $dbconn;
    }

}

?>